clear all

use "s2 data.dta"

*partisan identity
gen PID=pid
recode PID 1=2 2=6 3/4=4
recode PID 2=1 if pidd==1
recode PID 6=7 if pidr==1
recode PID 4=3 if pidi==1
recode PID 4=5 if pidi==2
gen PIDext=abs(PID-4)

*partisan social identity
recode demidentity* repidentity* (1=4) (2=3) (3=2) (4=1)
gen demid_sum=(demidentity_1+demidentity_2+demidentity_3+demidentity_4-4)/-12
gen repid_sum=(repidentity_1+repidentity_2+repidentity_3+repidentity_4-4)/12
egen PIDsocial=rowfirst(demid_sum repid_sum)
gen PIDsocial_ext=abs(PIDsocial)

*Trait aggression
recode BPAQ_1 1=6 2=5 3=4 4=3 5=2 6=1
recode BPAQ_3 1=6 2=5 3=4 4=3 5=2 6=1
recode BPAQ_4 1=6 2=5 3=4 4=3 5=2 6=1
recode BPAQ_5 1=6 2=5 3=4 4=3 5=2 6=1
alpha BPAQ*, item casewise asis gen(TraitAgg)


*1 = Camping ban (R, TX)
rename r_camp policy1
rename r_camp_impt impt1
rename r_camp_mc mc1

recode r_camp_agg* (1=5) (2=4) (4=2) (5=1)
alpha r_camp_agg_2 r_camp_agg_3 r_camp_agg_4 r_camp_agg_5, item casewise asis gen(aggdv1)

rename r_camp_agg_1 protest1
rename r_camp_agg_2 shout1
rename r_camp_agg_3 threat1
rename r_camp_agg_4 eggs1
rename r_camp_agg_5 punch1

*2 = Abortion ban (R, OK)
rename r_abortban policy2
rename r_abortban_impt impt2
rename r_abortban_mc mc2

recode r_abortban_agg* (1=5) (2=4) (4=2) (5=1)
alpha r_abortban_agg_2 r_abortban_agg_3 r_abortban_agg_4 r_abortban_agg_5, item casewise asis gen(aggdv2)

rename r_abortban_agg_1 protest2
rename r_abortban_agg_2 shout2
rename r_abortban_agg_3 threat2
rename r_abortban_agg_4 eggs2
rename r_abortban_agg_5 punch2

*3 = Constitutional Carry (R, TX)
rename r_carry policy3
rename r_carry_impt impt3
rename r_carry_mc mc3

recode r_carry_agg* (1=5) (2=4) (4=2) (5=1)
alpha r_carry_agg_2 r_carry_agg_3 r_carry_agg_4 r_carry_agg_5, item casewise asis gen(aggdv3)

rename r_carry_agg_1 protest3
rename r_carry_agg_2 shout3
rename r_carry_agg_3 threat3
rename r_carry_agg_4 eggs3
rename r_carry_agg_5 punch3

*4 = CRT (R, FL)
rename r_crt policy4
rename r_crt_impt impt4
rename r_crt_mc mc4

recode r_crt_agg* (1=5) (2=4) (4=2) (5=1)
alpha r_crt_agg_2 r_crt_agg_3 r_crt_agg_4 r_crt_agg_5, item casewise asis gen(aggdv4)

rename r_crt_agg_1 protest4
rename r_crt_agg_2 shout4
rename r_crt_agg_3 threat4
rename r_crt_agg_4 eggs4
rename r_crt_agg_5 punch4

*5 = Trans sports (R, FL)
rename r_transsport policy5
rename r_transsport_impt impt5
rename r_transsport_mc mc5

recode r_transsport_agg* (1=5) (2=4) (4=2) (5=1)
alpha r_transsport_agg_2 r_transsport_agg_3 r_transsport_agg_4 r_transsport_agg_5, item casewise asis gen(aggdv5)

rename r_transsport_agg_1 protest5
rename r_transsport_agg_2 shout5
rename r_transsport_agg_3 threat5
rename r_transsport_agg_4 eggs5
rename r_transsport_agg_5 punch5

*6 = Trans care (R, AL)
rename r_transcare policy6
rename r_transcare_impt impt6
rename r_transcare_mc mc6

recode r_transcare_agg* (1=5) (2=4) (4=2) (5=1)
alpha r_transcare_agg_2 r_transcare_agg_3 r_transcare_agg_4 r_transcare_agg_5, item casewise asis gen(aggdv6)

rename r_transcare_agg_1 protest6
rename r_transcare_agg_2 shout6
rename r_transcare_agg_3 threat6
rename r_transcare_agg_4 eggs6
rename r_transcare_agg_5 punch6

*7 = Sanctuary (D, WA)
rename d_sanct policy7
rename d_sanct_impt impt7
rename d_sanct_mc mc7

recode d_sanct_agg* (1=5) (2=4) (4=2) (5=1)
alpha d_sanct_agg_2 d_sanct_agg_3 d_sanct_agg_4 d_sanct_agg_5, item casewise asis gen(aggdv7)

rename d_sanct_agg_1 protest7
rename d_sanct_agg_2 shout7
rename d_sanct_agg_3 threat7
rename d_sanct_agg_4 eggs7
rename d_sanct_agg_5 punch7

*8 = Ethnic studies (D, CA)
rename d_ethnic policy8
rename d_ethnic_impt impt8
rename d_ethnic_mc mc8

recode d_ethnic_agg* (1=5) (2=4) (4=2) (5=1)
alpha d_ethnic_agg_2 d_ethnic_agg_3 d_ethnic_agg_4 d_ethnic_agg_5, item casewise asis gen(aggdv8)

rename d_ethnic_agg_1 protest8
rename d_ethnic_agg_2 shout8
rename d_ethnic_agg_3 threat8
rename d_ethnic_agg_4 eggs8
rename d_ethnic_agg_5 punch8

*9 = Cars (D, CA)
rename d_cars policy9
rename d_cars_impt impt9
rename d_cars_mc mc9

recode d_cars_agg* (1=5) (2=4) (4=2) (5=1)
alpha d_cars_agg_2 d_cars_agg_3 d_cars_agg_4 d_cars_agg_5, item casewise asis gen(aggdv9)

rename d_cars_agg_1 protest9
rename d_cars_agg_2 shout9
rename d_cars_agg_3 threat9
rename d_cars_agg_4 eggs9
rename d_cars_agg_5 punch9

*10 = Abortion haven (D, CA)
rename d_haven policy10
rename d_haven_impt impt10
rename d_haven_mc mc10

recode d_haven_agg* (1=5) (2=4) (4=2) (5=1)
alpha d_haven_agg_2 d_haven_agg_3 d_haven_agg_4 d_haven_agg_5, item casewise asis gen(aggdv10)

rename d_haven_agg_1 protest10
rename d_haven_agg_2 shout10
rename d_haven_agg_3 threat10
rename d_haven_agg_4 eggs10
rename d_haven_agg_5 punch10

*11 = Guns (D, CA)
rename d_guns policy11
rename d_guns_impt impt11
rename d_guns_mc mc11

recode d_guns_agg* (1=5) (2=4) (4=2) (5=1)
alpha d_guns_agg_2 d_guns_agg_3 d_guns_agg_4 d_guns_agg_5, item casewise asis gen(aggdv11)

rename d_guns_agg_1 protest11
rename d_guns_agg_2 shout11
rename d_guns_agg_3 threat11
rename d_guns_agg_4 eggs11
rename d_guns_agg_5 punch11

*12 = Ammo (D, WA)
rename d_ammo policy12
rename d_ammo_impt impt12
rename d_ammo_mc mc12

recode d_ammo_agg* (1=5) (2=4) (4=2) (5=1)
alpha d_ammo_agg_2 d_ammo_agg_3 d_ammo_agg_4 d_ammo_agg_5, item casewise asis gen(aggdv12)

rename d_ammo_agg_1 protest12
rename d_ammo_agg_2 shout12
rename d_ammo_agg_3 threat12
rename d_ammo_agg_4 eggs12
rename d_ammo_agg_5 punch12

*state used in scenario
forval x=1/12 {
gen treatstate`x'=""
}
replace treatstate1="TX"
replace treatstate2="OK"
replace treatstate3="TX"
replace treatstate4="FL"
replace treatstate5="FL"
replace treatstate6="AL"
replace treatstate7="WA"
replace treatstate8="CA"
replace treatstate9="CA"
replace treatstate10="CA"
replace treatstate11="CA"
replace treatstate12="WA"


**** reshaping

gen RespID=_n
reshape long policy impt mc angry aggdv protest shout threat eggs punch treatstate, i(RespID) j(scenario)

label define scenariol 1 "TX (R): Camping Ban" 2 "OK (R): Abortion Ban" 3 "TX (R): Constitutional Carry" 4 "FL (R): Critical Race Theory" 5 "FL (R): Transgender Sports" 6 "AL (R): Gender Affirmation" 7 "WA (D): Sanctuary City" 8 "CA (D): Ethnic Studies" 9 "CA (D): Gas Car Ban" 10 "CA (D): Abortion Haven" 11 "CA (D): Assault Ban" 12 "WA (D): Ammo Limit", replace
label values scenario scenariol

label variable protest "Protest the Governor"
label variable shout "Shout out of restaurant"
label variable threat "Threatening messages"
label variable eggs "Egg the Governor"
label variable punch "Punch the Governor"

recode policy 1=7 2=6 3=5 5=3 6=2 7=1
gen attext=abs(policy-4)
recode policy 1/3=1 4/7=0, gen(policydi)

*rescaling all vars to 0-1
replace mc=(mc-1)/4
replace impt=(impt-1)/4
replace attext=attext/3
replace PIDext=PIDext/3
replace TraitAgg=(TraitAgg-1)/5

*creating attitude intensity index
alpha mc attext impt, item casewise gen(intensity)

*creating mean and differenced scores for within-between
egen mc_mean=mean(mc) if policy<4, by(RespID)
egen impt_mean=mean(impt) if policy<4, by(RespID)
egen attext_mean=mean(attext) if policy<4, by(RespID)
egen intensity_mean=mean(intensity) if policy<4, by(RespID)
egen angry_mean=mean(angry) if policy<4, by(RespID)

*creating mean difference scores for within-between
gen mc_diff=mc-mc_mean
gen impt_diff=impt-impt_mean
gen attext_diff=attext-attext_mean
gen intensity_diff=intensity-intensity_mean
gen angry_diff=angry-angry_mean

*distribution of items
recode protest 1/3=0 4/5=1, gen(protestdi)
recode shout 1/3=0 4/5=1, gen(shoutdi)
recode threat 1/3=0 4/5=1, gen(threatdi)
recode eggs 1/3=0 4/5=1, gen(eggsdi)
recode punch 1/3=0 4/5=1, gen(punchdi)


*Figure 1

gen y=.
sum protestdi if policydi==1
replace y=r(mean) in 1
sum shoutdi if policydi==1
replace y=r(mean) in 2
sum eggsdi if policydi==1
replace y=r(mean) in 3
sum punchdi if policydi==1
replace y=r(mean) in 4
sum threatdi if policydi==1
replace y=r(mean) in 5
gen x=_n
replace x=. if _n>5
label define actionl 1 "Protest the Governor" 2 "Shout out of restaurant" 3 "Egg the Governor" 4 "Punch the Governor" 5 "Threatening messages", replace
label values x actionl
graph bar y, over(x,  label(labsize(small))) horiz ytitle("Proportion Supporting") subtitle("Support for Action (Study 2)") ylab(0(.1).7) saving(aggbyitem_S2.gph, replace)

gen supportcount=shoutdi+eggsdi+punchdi+threatdi
graph bar supportcount if policydi==1, over(scenario, sort((mean) supportcount) descending label(labsize(small))) horiz ytitle("Mean Number of Aggressive Actions Supported") subtitle("Support for Aggression by Policy (Study 2)") ylab(0(.1).5) saving(aggbypolicy_S2.gph, replace)

graph combine aggbyitem_S1.gph aggbypolicy_S1.gph aggbyitem_S2.gph aggbypolicy_S2.gph 


**attitude strength models 
mixed aggdv intensity_diff intensity_mean i.scenario if policy<4 || RespID: , vce(cluster RespID)
est store t20

mixed aggdv mc_diff mc_mean i.scenario if policy<4 || RespID: , vce(cluster RespID)
est store t21
lincomest mc_diff
est store mc1

mixed aggdv impt_diff impt_mean i.scenario if policy<4 || RespID: , vce(cluster RespID)
est store t22
lincomest impt_diff
est store impt1

mixed aggdv attext_diff attext_mean i.scenario if policy<4 || RespID: , vce(cluster RespID)
est store t23
lincomest attext_diff
est store ext1

mixed aggdv mc_diff mc_mean impt_diff impt_mean attext_diff attext_mean i.scenario if policy<4 || RespID: , vce(cluster RespID)
est store t24
lincomest mc_diff
est store mc2

mixed aggdv mc_diff mc_mean impt_diff impt_mean attext_diff attext_mean i.scenario if policy<4 || RespID: , vce(cluster RespID)
lincomest impt_diff
est store impt2

mixed aggdv mc_diff mc_mean impt_diff impt_mean attext_diff attext_mean i.scenario if policy<4 || RespID: , vce(cluster RespID)
lincomest attext_diff
est store ext2


coefplot (mc1, aseq("Moral Conviction") swapnames) (impt1, aseq("Importance") swapnames) (ext1, aseq("Extremity") swapnames subtitle("Study 2: Single-Predictor Models") legend(off) xlab(-.2(.2).6) xline(0) saving(strength_solo2.gph, replace))

coefplot (mc2, aseq("Moral Conviction") swapnames) (impt2, aseq("Importance") swapnames) (ext2, aseq("Extremity") swapnames subtitle("Study 2: Full Model") legend(off) xlab(-.2(.2).6) xline(0) saving(strength_full2.gph, replace))

graph combine strength_solo.gph strength_solo2.gph strength_full.gph strength_full2.gph, rows(2)



** table a3
mixed aggdv PIDext TraitAgg i.scenario if policy<4, vce(cluster RespID) || RespID:
est store a1

mixed aggdv PIDsocial_ext TraitAgg i.scenario if policy<4, vce(cluster RespID) || RespID:
est store a2

mixed aggdv c.intensity_diff##c.TraitAgg c.intensity_diff##c.PIDext intensity_mean i.scenario if policy<4, vce(cluster RespID) || RespID:
est store a3

margins, dydx(TraitAgg) at(intensity_diff=(-.59 .44) PIDext=.64)
margins, dydx(intensity_diff) at(TraitAgg=(0 1) PIDext=.64)


mixed aggdv c.intensity_diff##c.TraitAgg c.intensity_diff##c.PIDsocial_ext intensity_mean i.scenario if policy<4, vce(cluster RespID) || RespID:
est store a4

margins, dydx(TraitAgg) at(intensity_diff=(-.59 .44) PIDsocial_ext=.39)
margins, dydx(intensity_diff) at(TraitAgg=(0 1) PIDsocial_ext=.39)


*top middle
mixed aggdv c.intensity_diff##c.TraitAgg c.intensity_diff##c.PIDext intensity_mean i.scenario if policy<4, vce(cluster RespID) || RespID:

margins, at(TraitAgg=(0(.1)1) intensity_diff=(-.59 .44) PIDext=.64) vsquish
marginsplot, x(TraitAgg) recast(line) recastci(rarea) ci1opts(color(%30)) ci2opts(color(%30)) xtitle("Trait Aggression") ytitle("Support for Aggression", size(small)) ylab(1(1)4) ysc(range(0.85 4)) xlab(0(.25)1) title("") saving(TraitIntensity_intx_S2.gph, replace) legend(order(3 "Minimum Attitude Intensity" 4 "Maximum Attitude Intensity") rows(1) pos(6)) subtitle("Study 2 (Model 1)")

*bottom middle
margins, at(PIDext=(0(.1)1) intensity_diff=(-.59 .44) TraitAgg=.35) vsquish
marginsplot, x(PIDext) recast(line) recastci(rarea) ci1opts(color(%30)) ci2opts(color(%30)) xtitle(Partisan Strength) ytitle("Support for  Aggression", size(small)) ylab(1(1)4) ysc(range(0.85 4)) xlab(0(.25)1) title("") saving(PIDIntensity_intx_S2.gph, replace) subtitle("Study 2 (Model 1)")

*top right
mixed aggdv c.intensity_diff##c.TraitAgg c.intensity_diff##c.PIDsocial_ext intensity_mean i.scenario if policy<4, vce(cluster RespID) || RespID:

margins, at(TraitAgg=(0(.1)1) intensity_diff=(-.59 .44) PIDsocial_ext=.39) vsquish
marginsplot, x(TraitAgg) recast(line) recastci(rarea) ci1opts(color(%30)) ci2opts(color(%30)) xtitle(Trait Aggression) ytitle("Support for Aggression", size(small)) ylab(1(1)4) ysc(range(0.85 4)) xlab(0(.25)1) title("") saving(TraitIntensity_intx_S2b.gph, replace) legend(order(3 "Minimum Attitude Intensity" 4 "Maximum Attitude Intensity") rows(1) pos(6)) subtitle("Study 2 (Model 2)")

*bottom right
margins, at(PIDsocial_ext=(0(.1)1) intensity_diff=(-.59 .44) TraitAgg=.35) vsquish
marginsplot, x(PIDsocial_ext) recast(line) recastci(rarea) ci1opts(color(%30)) ci2opts(color(%30)) xtitle(Partisan Strength) ytitle("Support for  Aggression", size(small)) ylab(1(1)4) ysc(range(0.85 4)) xlab(0(.25)1) title("") saving(PIDIntensity_intx_S2b.gph, replace) subtitle("Study 2 (Model 2)")

*full figure
grc1leg TraitIntensity_intx_S1.gph TraitIntensity_intx_S2.gph TraitIntensity_intx_S2b.gph  PIDIntensity_intx_S1.gph PIDIntensity_intx_S2.gph PIDIntensity_intx_S2b.gph, leg(TraitIntensity_intx_S1.gph) 


*alternative fixed effects models - attitude strength
xtset RespID

xtreg aggdv intensity i.scenario if policy<4, fe cluster(RespID)
est store fe_t20

xtreg aggdv mc i.scenario if policy<4, fe cluster(RespID)
est store fe_t21

xtreg aggdv impt i.scenario if policy<4, fe cluster(RespID)
est store fe_t22

xtreg aggdv attext i.scenario if policy<4, fe cluster(RespID)
est store fe_t23

xtreg aggdv mc impt attext i.scenario if policy<4, fe cluster(RespID)
est store fe_t24


*alternative fixed effects models - interactions
xtreg aggdv c.intensity_diff##c.TraitAgg c.intensity_diff##c.PIDext intensity_mean i.scenario if policy<4, fe cluster(RespID)

xtreg aggdv c.intensity_diff##c.TraitAgg c.intensity_diff##c.PIDsocial_ext intensity_mean i.scenario if policy<4, fe cluster(RespID)


*effects of exclusions on covariates
twoway kdensity PIDsocial_ext if policy<8, bwidth(.1) || kdensity PIDsocial_ext if policy<4, bwidth(.1) legend(pos(6) order(1 "Full Sample" 2 "Effective Sample") rows(1)) xtitle("Strength of Partisan Social ID") ytitle(Density) saving(excl_pidsocial_S2.gph, replace)

twoway (hist PIDext if policy<8, width(.25) color(green%30)) (hist PIDext if policy<4, width(.25) color(red%30) xlab(.125 "Independent" .375 "Leaner" .625 "Weak" .875 "Strong") xtitle("Strength of Partisan ID") legend(pos(6) order(1 "Full Sample" 2 "Effective Sample") rows(1)) saving(excl_pidext_S2.gph, replace))

twoway kdensity TraitAgg if policy<8, bwidth(.1) || kdensity TraitAgg if policy<4, bwidth(.1) legend(pos(6) order(1 "Full Sample" 2 "Effective Sample") rows(1)) xtitle("Trait Aggression") ytitle(Density) saving(excl_agg_S2.gph, replace)

graph combine excl_pidext_S2.gph excl_pidsocial_S2.gph excl_agg_S2.gph



